package com.mall.controller;

import com.mall.domain.dto.PaymentDTO;
import com.mall.domain.dto.PaymentPageQueryDTO;
import com.mall.domain.po.Payment;
import com.mall.domain.vo.PaymentVO;
import com.mall.result.PageResult;
import com.mall.result.Result;
import com.mall.service.PaymentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 支付控制器
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/25 14:45
 */
@RestController
@RequestMapping("/payment")
@RequiredArgsConstructor
@Tag(name = "支付管理", description = "支付管理相关接口")
public class PaymentController {

    private final PaymentService paymentService;

    /**
     * 支付
     * @param paymentDTO 支付传输对象
     * @return 结果
     */
    @PutMapping("/pay")
    @Operation(summary = "支付")
    public Result<String> pay(@RequestBody PaymentDTO paymentDTO) {
        paymentService.pay(paymentDTO);
        return Result.success("支付成功");
    }

    /**
     * 查看历史支付记录
     * @param paymentPageQueryDTO 分页查询传输对象
     * @return 结果
     */
    @PostMapping("/history")
    @Operation(summary = "查看历史支付记录")
    public Result<PageResult<PaymentVO>> historyPayment(@RequestBody PaymentPageQueryDTO paymentPageQueryDTO) {
        PageResult<PaymentVO> pageResult = paymentService.historyPayment(paymentPageQueryDTO);
        return Result.success(pageResult);
    }
}
